/*####################################################################################
  CLASS : mydojo.dijix.FormDialog
  =============================
  - Form inside a dialog
  ####################################################################################*/
  
dojo.provide("mydojo.dijix.FormDialog");

dojo.require("dijit.Dialog");
dojo.require("mydojo.dijix.FormFactory");

dojo.declare("mydojo.dijix.FormDialog", dijit.Dialog , {
				
		formStruct : null,		
		method: "POST",
		action: "dummy" ,
		hasFile: false ,
		submitLabel: "Save" ,								
		submitLabel	: "Submit" , 
		cancelLabel	: "Cancel" ,
		clearLabel	: "Clear" ,		
		showCancel	: true,
		showClear	: false,
		
		viewName: null ,
		// ---------------------
		form : null,		
		
		// ======================================================================
		//	Post create widget 
		// ----------------------------------------------------------------------
		postCreate: function() {		
			this.inherited(arguments);				
			this.form = new mydojo.dijix.FormFactory( {	id: this.id+"FF",
														formStruct: this.formStruct , 
														formId: 	this.id, 
														method: 	this.method, 
														action: 	this.action,
														hasFile: 	this.hasFile,
														submitLabel:this.submitLabel,
														cancelLabel:this.cancelLabel,
														clearLabel: this.clearLabel,
														showCancel: this.showCancel,
														showClear: 	this.showClear
													 } );							
			this.containerNode.appendChild(this.form.domNode);									
			dojo.connect(this.form , "submitClicked" , this , "submit");									
			dojo.connect(this.form , "cancelClicked" , this , "hide");			
			this.show();			
		},	
		// ======================================================================
		//	Override Hide to Destroy the dialog
		// ----------------------------------------------------------------------
		hide: function(){					
			this.form.destroyDescendants();
			this.form.destroy();
			this.destroy();
		},
		// ======================================================================
		//	For cascading  effect only
		// ----------------------------------------------------------------------
		submit: function(){},
		// ======================================================================
		//	Dispatch form and destroy form
		// ----------------------------------------------------------------------  
		dispatch: function(id){
			if(this.form.dispatch(id) > 0)	
				this.hide();
		}
});
